<?php

define('G_OUTPUT_REQUEST_AUTH_KEY', 1);
define('G_BIN_CHECK_INCLUDE', 1);

include('./common.inc.php');

if(empty($_G_INPUT_['state']) || empty($_G_INPUT_['code']))
{
	die('error');
}

if(strpos($_G_INPUT_['state'], '-QQ'))
{
	// Tencent
	$thirdPartyObj = Bin::singtolen('QQLoginClass', 'Common');
	$accessToken = $thirdPartyObj->getAccessToken($_G_INPUT_['code']);
	$OpenID = $thirdPartyObj->getOpenID($accessToken);
	$thirdPartyTag = 'Tencent';
}
elseif(strpos($_G_INPUT_['state'], '-Sina'))
{
	// Sina
	$thirdPartyObj = Bin::singtolen('SinaLoginClass', 'Common');
	$thirdPartyObj->getAccessToken($_G_INPUT_['code']);
	$openID = $thirdPartyObj->getOpenID();
	$thirdPartyTag = 'Sina';
}



$userInfo = $G_USER_OBJ->getBindIdInfo($OpenID, $thirdPartyTag);
if(empty($userInfo))
{
	header('HTTP/1.0 302');
	header("Location: bindUserID.php?thirdPartyTag={$thirdPartyTag}&openID={$OpenID}");
	die;
}
p($userInfo ,$G_USER_OBJ->quickLogin($userInfo['id'], G_CLIENT_IP, 'onLine'));

